import {
    Request
  } from "../../../wxParse/request.js"
  const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        statusBarHeight: getApp().globalData.statusBarHeight,
    },
    toown:function(){
        wx.navigateBack({
          delta: 1,
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
    //获取用户地址和手机信息
    new Request('User/GetUserAddressInfo').request(
        () => {
            return {
                openid: app.globalData.openid,    //用户openid
            }
        },
        (res) => {
            if(res.data.data != -5){
                this.setData({
                    UserInfo:res.data.data,
                    phone: res.data.data.userPhone,
                    address: res.data.data.userAddress,
                });
            }else{
                wx.showToast({
                title: '还没有授权',
                icon: 'none',
                duration: 2000
                });
            }
        });
    },
    /**
     * 获取输入框输入值
     */
    _GetInputInfo:function(param){
        if(param.target.id == "phone"){
            this.data.phone = param.detail.value;
        }
        if(param.target.id == "address"){
            this.data.address = param.detail.value;
        }
    },
    /**
     * 提交修改 用户地址
     */
    _buttonUpdate:function(param){
        if(!this.data.phone == '' || !typeof(this.data.phone) == 'undefined'){
            if(!this.data.address == '' || typeof(this.data.address) == 'undefined'){
                //上传收货地址
                new Request('User/UpdateChouUserAddres').request(
                    () => {
                        return {
                            openid: app.globalData.openid,    //用户openid
                            userPhone: this.data.phone,      //用户手机号
                            userAddress: this.data.address,      //用户地址
                        }
                    },
                    (res) => {
                        if(res.data.data){
                            wx.showToast({
                                title: '提交成功',
                                icon: 'none',
                                duration: 2000
                            });
                            setTimeout(()=>{
                                wx.navigateBack({
                                    delta: 1,
                                  })
                            },2001);
                        }else{
                            wx.showToast({
                                title: '提交失败',
                                icon: 'none',
                                duration: 2000
                            });
                        }
                    });
            }else{
                wx.showToast({
                    title: '请输入地址',
                    icon: 'none',
                    duration: 2000
                });
            }
        }else{
            wx.showToast({
                title: '请输入手机',
                icon: 'none',
                duration: 2000
            });
            wx.chooseAddress({
                success: (res) => {
                    if (res.telNumber || res.cityName || res.countyName || res.detailInfo) {
                        this.phone = res.telNumber;
                        this.address = res.provinceName + res.cityName + res.countyName + res.detailInfo;
                        this.setData({
                            phone: this.phone,
                            address: this.address,
                        });
                    }
                },
            });
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})